package cn.wolfcode.mq;

import cn.wolfcode.domain.OrderInfo;
import cn.wolfcode.mapper.OrderInfoMapper;
import cn.wolfcode.service.IOrderInfoService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(
        consumerGroup = "MQOrderPayTimeListener",
        topic = MQConstant.ORDER_PAY_TIMEOUT_TOPIC
)
public class MQOrderPayTimeListener implements RocketMQListener<OrderMQResult> {
    @Autowired
    private OrderInfoMapper orderInfoMapper;
    @Autowired
    private IOrderInfoService orderInfoService;
    @Override
    public void onMessage(OrderMQResult orderMQResult) {
        //判断订单是否处于未支付状态
        OrderInfo orderInfo = orderInfoMapper.find(orderMQResult.getOrderNo());
        if (orderInfo != null) {
            if (OrderInfo.STATUS_ARREARAGE.equals(orderInfo.getStatus())) {
                orderInfoService.coverStock(orderMQResult);
            }
        }
    }
}
